<?php
    
    
    include_once "include/constants.php";
	
    if (!defined('IS_AJAX')) {
        define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
    }

	if (IS_AJAX && !isset($_GET["userid"])) {
        die("Give me params!!!");
    }

    try {
        $conn = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PASS);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
        if (isset($_GET["userid"])) $thumbs_UserId = $_GET["userid"];
         
        $stmt = $conn->prepare('select * from thumbs where userid = :userid');
		$stmt->execute(array("userid" => $thumbs_UserId));
        
        $thumbs_data = array();
        while ($thumbs_row = $stmt->fetch()) {
            $thumbs_data[] = $thumbs_row;
        }
        
        if (IS_AJAX) echo json_encode($thumbs_data);
        else echo "<script>my_thumbs = ".json_encode($thumbs_data)."</script>";
        
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
    
?>
